<template>
	<el-dialog :title="!dataForm.id ? '新建' :  isDetail ? '详情':'编辑'" :close-on-click-modal="false" :visible.sync="visible" class="JNPF-dialog JNPF-dialog_center" lock-scroll width="800px">
		<el-row :gutter="15" class="" >
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="124px" label-position="right" :disabled="!!isDetail" >
				<!-- <el-col :span="24">
					<el-form-item label="风险计划名称" prop="jhid">
						<el-select v-model="dataForm.jhid" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in ssbmOptions" :key="index" :label="item.JHMC" :value="item.ID" ></el-option>
						</el-select>
					</el-form-item>
				</el-col> -->
				<el-col :span="12">
					<el-form-item label="风险点" prop="fxdid">
						<el-select v-model="dataForm.fxdid" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in fxdOptions" :key="index" :label="item.mc" :value="item.Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="风险点类型" prop="fxdlx">
						<el-select v-model="dataForm.fxdlx" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in fxdlxOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="检查项目" prop="jcxm" v-if="dataForm.fxdlx == 0">
						<el-input v-model="dataForm.jcxm" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="检查标准" prop="jcbz" v-if="dataForm.fxdlx == 0">
						<el-input v-model="dataForm.jcbz" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="不符合标准情况" prop="bfhbzqk" v-if="dataForm.fxdlx == 0">
						<el-input v-model="dataForm.bfhbzqk" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="主要后果" prop="zyhg" v-if="dataForm.fxdlx == 0 || dataForm.fxdlx == 2">
						<el-input v-model="dataForm.zyhg" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="作业步骤" prop="zybz" v-if="dataForm.fxdlx == 1">
						<el-input v-model="dataForm.zybz" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="危险源或潜在事件" prop="wxyhqzsj" v-if="dataForm.fxdlx == 1">
						<el-input v-model="dataForm.wxyhqzsj" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="事故类型及后果" prop="knfsdsjlxjhg" v-if="dataForm.fxdlx == 1">
						<el-input v-model="dataForm.knfsdsjlxjhg" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="节点" prop="jd" v-if="dataForm.fxdlx == 2">
						<el-input v-model="dataForm.jd" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="参数" prop="cs" v-if="dataForm.fxdlx == 2">
						<el-input v-model="dataForm.cs" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="参数描述" prop="csms" v-if="dataForm.fxdlx == 2">
						<el-input v-model="dataForm.csms" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="引导词" prop="ydc" v-if="dataForm.fxdlx == 2">
						<el-input v-model="dataForm.ydc" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="可能原因" prop="knyy" v-if="dataForm.fxdlx == 2">
						<el-input v-model="dataForm.knyy" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="偏差" prop="pc" v-if="dataForm.fxdlx == 2">
						<el-input v-model="dataForm.pc" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="工程技术措施" prop="gcjscs" >
						<el-input v-model="dataForm.gcjscs" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="管理措施" prop="glcs" >
						<el-input v-model="dataForm.glcs" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="培训教育措施" prop="pxjycs" >
						<el-input v-model="dataForm.pxjycs" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="个体防护措" prop="gtfhcs" >
						<el-input v-model="dataForm.gtfhcs" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="应急处置措施" prop="yjczcs" >
						<el-input v-model="dataForm.yjczcs" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="风险等级" prop="fxdj" >
						<el-input v-model="dataForm.fxdj" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="风险值" prop="fxz" >
						<el-input v-model="dataForm.fxz" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="状态" prop="zt" >
						<el-select v-model="dataForm.zt" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in ztOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="管控层级" prop="gkcj" >
						<el-input v-model="dataForm.gkcj" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
			</el-form>
		</el-row>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取 消</el-button> 
			<el-button type="primary" @click="dataFormSubmit()">确 定</el-button>
		</span>
	</el-dialog>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
        dataForm: {
					id:undefined,
					jhid:undefined,
					fxdid:undefined,
					fxdlx:undefined,
					jcxm:undefined,
					jcbz:undefined,
					bfhbzqk:undefined,
					zyhg:undefined,
					zybz:undefined,
					wxyhqzsj:undefined,
					knfsdsjlxjhg:undefined,
					jd:undefined,
					cs:undefined,
					csms:undefined,
					ydc:undefined,
					knyy:undefined,
					pc:undefined,
					gcjscs:undefined,
					glcs:undefined,
					pxjycs:undefined,
					gtfhcs:undefined,
					yjczcs:undefined,
					fxdj:undefined,
					fxz:undefined,
					zt:undefined,
					gkcj:undefined,

        },
				ssbmOptions:[],
				fxdOptions:[],
				fxdlxOptions:[{"fullName":"设备设施","id":"0"},{"fullName":"作业活动","id":"1"},{"fullName":"工艺节点","id":"2"}],
				ztOptions:[{"fullName":"未评价","id":"0"},{"fullName":"已评价","id":"1"}],
      }
    },
    created() {
      this.getssbmOptions()
      this.getfxdOptions()
    },
    methods: {
			getssbmOptions() {
			previewDataInterface('c77c5bd16ec4445187a9d9474f6d3ad8').then(res => {
				this.ssbmOptions = res.data
			})
		},
		getfxdOptions() {
			previewDataInterface('aa8f673fa506428eac6adb219a22551d').then(res => {
				this.fxdOptions = res.data
			})
		},
      init(id, isDetail) {
        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/riskPlanpointcheck/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
							this.dataForm = res.data;
							this.dealValue('gcjscs')
							this.dealValue('glcs')
							this.dealValue('gtfhcs')
							this.dealValue('pxjycs')
							this.dealValue('yjczcs')
            })
          }
        })
      },
			// 数据处理
			dealValue(name){
        let list =	JSON.parse(this.dataForm[name]).map(item => item.value)
				this.dataForm[name] =list.toString();
			},
      // 表单提交
      dataFormSubmit() {
        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              // request({
              //   url: '/api/System/riskPlanpointcheck',
              //   method: 'post',
              //   data: this.dataForm,
              // }).then((res) =>{
              //   this.$message({
              //     message: res.msg,
              //     type: 'success',
              //     duration: 1000,
              //     onClose: () =>{
              //       this.visible = false;
              //       this.$emit('refresh', true);
              //     }
              //   })
              // })
            } else {
              request({
                url: '/api/System/riskPlanpointcheck/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
								this.$message({
									message: res.msg,
                  type: 'success',
                  duration: 1000,
									onClose: () =>{
										this.visible = false;
										this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },

    }
  }
  </script>
	<<style scoped>
	.el-dialog__body {
    height: auto;
}
	</style>